package cn.johnyu.springboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.johnyu.springboot.bean.User;
import cn.johnyu.springboot.dao.UserDao;

@Controller
public class UserController {
	public UserController() {
		System.out.println("user controller.....");
	}
	@Autowired
	private UserDao ud;
	@RequestMapping("/users")
	@ResponseBody
	public List<User> findAllUsers() {
		return ud.findAllUsers();
	}
	@ResponseBody
	@RequestMapping(value="/users",method=RequestMethod.POST,consumes="application/json")
	public User addUser(@RequestBody User u) {
		ud.addUser(u);
		return u;
	}
}
